package com.mingweicai.intergration.kafka;

import java.util.Properties;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class Producer {

  public static void main(String args[]){
    Properties properties = new Properties();
    properties.put("bootstrap.servers", "localhost:9092");
    properties.put("acks", "all");
    properties.put("retries", 0);
    properties.put("batch.size", 16384);
    properties.put("linger.ms", 1);
    properties.put("buffer.memory", 33554432);
    properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    KafkaProducer<String, String> kafkaProducer = new KafkaProducer<String, String>(properties);
    for (int i = 1; i <= 600; i++) {
      //参数1：topic名, 参数2：消息文本； ProducerRecord多个重载的构造方法
      kafkaProducer.send(new ProducerRecord<String, String>("kafka-action", "message"+i));
      System.out.println("message"+i);
    }
    kafkaProducer.close();
  }
}
